home *** CD-ROM | disk | FTP | other *** search
- #define __SRC__
- #include "lib.h"
- #include <minix/const.h>
- #include <minix/com.h>
- #include <termio.h>
- #include <minix/screen.h>
- #include <minix/stboots.h>
- #include <errno.h>
-
- #ifndef WANT_WENK_RS232
- static int o_ioctl();
-
- /* ioctl does termio emulation work, passes the rest to o_ioctl */
-
- int ioctl(fd,command,term)
- int fd;
- int command;
- struct termio *term;
- {
- int i;
- int r;
- char *cp;
- struct sgttyb b;
- struct tchars c;
- unsigned short iflag, oflag, cflag, lflag, baud;
-
-
- iflag = oflag = cflag = lflag = 0;
- switch(command) {
- case TCGETA:
- if((r = o_ioctl(fd,TIOCGETP, &b)) < 0)
- goto error;
- if((r = o_ioctl(fd,TIOCGETC, &c)) < 0)
- goto error;
- for(cp=(char*)term,i=0;i<(int)sizeof(*term);i++)
- *cp++ = 0;
- if(b.sg_flags & RAW) { /* raw over rides */
- iflag = 0;
- cflag = CS8;
- lflag = 0;
- oflag = 0;
- } else {
- oflag = CR0|OPOST;
- iflag = (BRKINT|IGNPAR|ISTRIP|IXON);
- cflag = CS7|PARENB|CREAD;
- lflag = 0;
- if((b.sg_flags & CBREAK ) == 0)
- lflag |= ICANON;
- if(b.sg_flags & ECHO)
- lflag |= ECHO;
- if(b.sg_flags & XTABS)
- oflag |= TAB3;
- if(b.sg_flags & CRMOD) {
- oflag |= ONLCR;
- iflag |= ICRNL;
- }
- }
- baud = b.sg_ispeed & 0xf;
- cflag |= baud;
- term->c_iflag = iflag;
- term->c_oflag = oflag;
- term->c_cflag = cflag;
- term->c_lflag = lflag;
- term->c_cc[VINTR] = c.t_intrc;
- term->c_cc[VQUIT] = c.t_quitc;
- term->c_cc[VERASE] = b.sg_erase;
- term->c_cc[VKILL] = b.sg_kill;
- term->c_cc[VEOF] = c.t_eofc;
- term->c_cc[VEOL] = '\0';
- term->c_cc[VEOL2] = c.t_brkc? c.t_brkc: '\n';
- break;
-
- case TCSETA:
- case TCSETAW:
- case TCSETAF:
- for(cp=(char*)&b,i=0;i<(int)sizeof(b);i++)
- *cp++ = 0;
- for(cp=(char*)&c,i=0;i<(int)sizeof(c);i++)
- *cp++ = 0;
- if(((term->c_iflag & (BRKINT|IGNPAR|ISTRIP|IXON))== 0) && /* raw */
- ((term->c_oflag & OPOST)==0) )
- b.sg_flags |= RAW;
- else {
- if(term->c_oflag & (TAB3))
- b.sg_flags |= XTABS;
- if(term->c_lflag & ECHO)
- b.sg_flags |= ECHO;
- if((term->c_lflag & ICANON)==0)
- b.sg_flags |= CBREAK;
-
- if(term->c_oflag & ONLCR || term->c_iflag & ICRNL)
- b.sg_flags |= CRMOD;
- }
- baud = term->c_cflag & CBAUD;
- b.sg_ispeed |= baud;
-
- c.t_intrc = term->c_cc[VINTR];
- c.t_quitc = term->c_cc[VQUIT];
- b.sg_erase = term->c_cc[VERASE];
- b.sg_kill = term->c_cc[VKILL];
- c.t_eofc = term->c_cc[VEOF];
- c.t_brkc = term->c_cc[VEOL];
- c.t_startc = '\021'; /* ^Q */
- c.t_stopc = '\023'; /* ^S */
-
- if((r = o_ioctl(fd,TIOCSETP, &b)) < 0)
- goto error;
- if((r = o_ioctl(fd,TIOCSETC, &c)) < 0)
- goto error;
- /* fall thru */
-
- case TCSBRK:
- case TCFLSH:
- r = o_ioctl(fd,command,(char*)0);
- break;
-
- case TCXONC: /* output if term=0 off, if term=1, on */
-
- default:
- r = o_ioctl(fd,command,term);
- break;
- }
- return(r);
-
- error:
- return(r);
- }
- #endif
-
-
- #ifndef WANT_WENK_RS232
- PRIVATE int o_ioctl(fd, request, u)
- #else
- PUBLIC int ioctl(fd, request, u)
- #endif
- int fd;
- int request;
- union {
- struct sgttyb *argp;
- struct tchars *argt;
- long arg;
- struct scr_param *args1;
- struct scr_palette *args2;
- struct block0 *argsbs;
- struct part *argspart;
- } u;
-
- {
- int n;
- long erase, kill, intr, quit, xon, xoff, eof, brk, speed;
- #ifdef WANT_WENK_RS232
- int ispeed, ospeed;
- #endif
-
- M.TTY_REQUEST = request;
- M.TTY_LINE = fd;
-
- switch(request) {
- case TIOCSETP:
- erase = u.argp->sg_erase & BYTE;
- kill = u.argp->sg_kill & BYTE;
- #ifdef WANT_WENK_RS232
- M.TTY_SPEK = (erase << 8) | kill;
- M.TTY_FLAGS = u.argp->sg_flags;
- M.TTY_FLAGS |= (( u.argp->sg_ospeed << 8 ) | u.argp->sg_ispeed ) << 16L;
- #else
- speed = u.argp->sg_ispeed & 0377;
- M.TTY_SPEK = (speed << 16) | (erase << 8) | kill;
- M.TTY_FLAGS = u.argp->sg_flags;
- #endif
- n = callx(FS, IOCTL);
- return(n);
-
- case TIOCSETC:
- intr = u.argt->t_intrc & BYTE;
- quit = u.argt->t_quitc & BYTE;
- xon = u.argt->t_startc & BYTE;
- xoff = u.argt->t_stopc & BYTE;
- eof = u.argt->t_eofc & BYTE;
- brk = u.argt->t_brkc & BYTE; /* not used at the moment */
- M.TTY_SPEK = (intr<<24) | (quit<<16) | (xon<<8) | (xoff<<0);
- M.TTY_FLAGS = (eof<<8) | (brk<<0);
- n = callx(FS, IOCTL);
- return(n);
-
- case TIOCGETP:
- n = callx(FS, IOCTL);
- u.argp->sg_erase = (M.TTY_SPEK >> 8) & BYTE;
- u.argp->sg_kill = (M.TTY_SPEK >> 0) & BYTE;
- #ifdef WANT_WENK_RS232
- u.argp->sg_flags = M.TTY_FLAGS;
- u.argp->sg_ospeed = M.TTY_FLAGS >> 24;
- u.argp->sg_ispeed = M.TTY_FLAGS >> 16;
- #else
- u.argp->sg_ispeed = (M.TTY_SPEK >> 16) & 0377;
- u.argp->sg_flags = M.TTY_FLAGS;
- #endif
- return(n);
-
- case TIOCGETC:
- n = callx(FS, IOCTL);
- u.argt->t_intrc = (M.TTY_SPEK >> 24) & BYTE;
- u.argt->t_quitc = (M.TTY_SPEK >> 16) & BYTE;
- u.argt->t_startc = (M.TTY_SPEK >> 8) & BYTE;
- u.argt->t_stopc = (M.TTY_SPEK >> 0) & BYTE;
- u.argt->t_eofc = (M.TTY_FLAGS >> 8) & BYTE;
- u.argt->t_brkc = (M.TTY_FLAGS >> 8) & BYTE;
- return(n);
-
- case SCRSETPARAM:
- case SCRGETPARAM:
- case SCRSETCOLOR:
- case SCRGETCOLOR:
- M.TTY_SPEK = (long) u.args1;
- n = callx(FS, IOCTL);
- return(n);
-
- /* for disk-clock */
- case DC_RBMS100:
- case DC_RBMS200:
- case DC_RSUPRA:
- case DC_RICD:
- case DC_WBMS100:
- case DC_WBMS200:
- M.TTY_SPEK = u.arg; /* this is address to write ans to */
- n = callx(FS, IOCTL);
- return(n);
-
- /* for floppy/hard disk */
- case DKGETP: /* get struct block0 */
- M.TTY_SPEK = (long)u.argsbs;
- n = callx(FS, IOCTL);
- return(n);
- case DKPART: /* get struct part */
- M.TTY_SPEK = (long)u.argspart;
- n = callx(FS, IOCTL);
- return(n);
- case DKOPEN: /* open disk after a DKCLOSE */
- M.TTY_SPEK = 0L;
- n = callx(FS, IOCTL);
- return(n);
- case DKCLOSE: /* close out disk */
- M.TTY_SPEK = (long)0L;
- n = callx(FS, IOCTL);
- return(n);
-
- #ifndef WANT_WENK_RS232
- case TIOCSTART:
- n = callx(FS, IOCTL);
- return(n);
-
- case TIOCSTOP:
- n = callx(FS, IOCTL);
- return(n);
-
- /* taken from termio for rs232 */
- case TCSETAW: /* wait for output to drain */
- case TCSETAF: /* wait for output to dran, then flush input */
- case TCSBRK: /* drain output, send a break */
- case TCXONC: /* start/stop output arg ==0 stop, ==1 start */
- case TCFLSH: /* flush: 0==input 1==output 2=both */
- M.TTY_SPEK = u.arg & 0377;
- n = callx(FS, IOCTL);
- return(n);
- case FIONREAD: /* return num chars in read Q */
- case TCFLOWON:
- case TCFLOWOFF:
- case TCFLOW:
- case TCSETDTR: /* arg ....xy; x=rts, y=dtr */
- M.TTY_SPEK = u.arg; /* this is address to write ans to */
- n = callx(FS, IOCTL);
- return(n);
- case TCGETRS:
- M.TTY_SPEK = u.arg; /* this is address to write ans to */
- n = callx(FS, IOCTL);
- return(n);
- #endif
-
- default:
- n = -1;
- errno = (EINVAL);
- return(n);
- }
- }
-
-